﻿<?php
/*
 * 用户中心
 * 1、作品评论
 * 2、作品点赞
 */
require_once '../init.php';
define('TEMPLATE_PATH', WANYA_ROOT . '/m/view/');

$flg = $_REQUEST["flg"];
$Productions_Model = new Productions_Model();

// 点赞 - 需要判断是否过关 增加总的热度
if ($flg == 1) {
    $result = array();
    $voteProductionData = array();
    $voteProductionData["openid"] = $_POST["openid"];
    $voteProductionData["head_img_url"] = $_POST["head_img_url"];
    $voteProductionData["production_id"] = $_POST["production_id"];
    $Productions_Model->voteProduction($voteProductionData);

    $productionDetail = $Productions_Model->getProductionDetails($voteProductionData["production_id"]);

    $Activity_Model = new Activity_Model();
    $Productions_Model = new Productions_Model();
    $User_Info_Model = new User_Info_Model();
    $User_Master_Model = new User_Master_Model();

    $userInfo = $User_Info_Model->getUserInfo($openid);

    // 检索活动报名的状态
    $applyState = $Activity_Model->getActivityApplyState($userInfo["uid"], $productionDetail["activity_id"]);

    // 检索当前关卡需要的文件和赞数
    $need = $Activity_Model->getActivityNeed($productionDetail["activity_id"], $applyState);

    // 检索用户在这个活动下 上传的文件的总数 和 总的赞数
    $all = $Productions_Model->getProductionCount($productionDetail["activity_id"], $openid);

    // 判断是否过关 - 过关
    if ($all["productionSum"] >= $need["productionSum"] && $all["voteSum"] >= $need["voteSum"]) {
        $Activity_Model->updateActivityApplyState($userInfo["uid"], $productionDetail["activity_id"]);
    }

    // 加热度
    $userMasterData["family_id"] = $userInfo["family_id"];
    $User_Master_Model->updateUserMasterHot($userMasterData);

    $result["result"] = true;
    echo json_encode($result);
}

// 品论
if ($flg == 2) {
    $result = array();
    $replyProductionData = array();
    $replyProductionData["openid"] = $_POST["openid"];
    $replyProductionData["head_img_url"] = $_POST["head_img_url"];
    $replyProductionData["production_id"] = $_POST["production_id"];
    $replyProductionData["content"] = $_POST["content"];
    $Productions_Model->replyProduction($replyProductionData);
    $result["result"] = true;
    echo json_encode($result);
}
?>

